//
//  EMMStatisticalAnalysisViewController.m
//  EMMApp
//
//  Created by Mac on 17/1/5.
//  Copyright © 2017年 YiXun. All rights reserved.
//

#import "EMMStatisticalAnalysisViewController.h"
/** ViewController
 *
 *  首页ViewController导入.h文件
 */
#import "DealPropertyTypeAnalysisViewController.h"  //成交房产类型分析
#import "WorkloadStatisticsViewController.h"        //工作量统计
#import "StockTimeAnalysisViewController.h"         //存量时间分析
#import "StockAvailabilityViewController.h"         //存量房源分析
#import "EMMNotSignedBackViewController.h"          //签约未回款
#import "EMMSalesTargetViewController.h"            //销售指标
#import "CalculationPAViewController.h"             //算价
#import "EMMAnalysisViewController.h"               //客户分析
#import "ProjectModel.h"                            //项目对象
#import "ShotImage.h"
#import "ChooseView.h"

/** Cell
 *
 *  首页Cell导入.h文件
 */
#import "StatisticalAnalysisOneCell.h"
#import "StatisticalAnalysisCell.h"                 //Cell
#import "DecisionOneCellColl.h"
#import "EMMNewDecisionCell.h"
#import "NewCustomersCell.h"
#import "DecisionOneCell.h"
#import "MarketingCell.h"

/** Api
 *
 *  首页Api调用导入.h文件
 */
#import "GetMemberScoreListApi.h"
#import "GetTimeConditionAnalysisApi.h"


@interface EMMStatisticalAnalysisViewController ()<UITableViewDelegate,UITableViewDataSource,StatisticalAnalysisOneCellDelegate>
{
    NSString *timer;
    NSString *tierXZA;
    //判断导航
    BOOL _isShowUI;
    NSMutableDictionary *dic;//存对应的数据
    NSMutableArray *selectedArr;//二级列表是否展开状态
    NSMutableArray *grouparr;
    
    UIImage *shotImage;//分析图片
    NSString *sfCZString;
}
@property (nonatomic, strong) UITableView *statisticalAnalysisTableView;

@property (nonatomic, strong) NSString *rcScoreNum;

@property (nonatomic, strong) NSString *rgScoreNum;

@property (nonatomic, strong) NSString *qyScoreNum;

@property (nonatomic, strong) MenuLitsView *menuD;//导航
@property (nonatomic, strong) NSMutableArray *menuListD;//导航数组

@property (nonatomic, strong) NSMutableArray *menuArrD;//导航数组

@property (nonatomic, strong) UICollectionView *homeCollectionView;

@property (nonatomic, strong) GetTimeConditionAnalysis *getTimeConditionAnalysis;

@property (nonatomic, strong) StatisticalAnalysisCell *staisCell;

@property (nonatomic, strong) NSString *timerString;//成绩时间

@property (nonatomic, strong) NSString *cjKSTimerString;//成绩开始时间
@property (nonatomic, strong) NSString *cjKSTimer1String;//成绩开始时保存原有时间格式

@property (nonatomic, strong) NSString *cjJSTimerString;//成绩结束时间
@property (nonatomic, strong) NSString *cjJSTimer1String;//成绩结束时间保存原有时间格式


@property (nonatomic, strong) NSString *mTimerString;//月指标

@property (nonatomic, strong) NSString *mzbSKTimerString;//月指标开始时间
@property (nonatomic, strong) NSString *mzbSKTimer1String;//月指标开始时间保存原有时间格式

@property (nonatomic, strong) NSString *mzbJSTimerString;//月指标结束时间
@property (nonatomic, strong) NSString *mzbJSTimer1String;//月指标结束时间保存原有时间格式

@property (nonatomic, strong) NSString *yTimerString;//年指标

@property (nonatomic, strong) ChooseView *cView;

@property (nonatomic, strong) NSString *timerNameStr;

@end

@implementation EMMStatisticalAnalysisViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorFromHexCode:@"#f7f7f7"];
    selectedArr = [NSMutableArray arrayWithObjects:@"2", nil];
    grouparr = [NSMutableArray arrayWithObjects:@"成交房产类型分析",@"存量时间分析",@"成交房源分析",@"存量房源分析",@"算价分析", nil];
    _statisticalAnalysisTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH,EMM_HEIGHT-SafeAreaTopHeight-SafeAreaBottomHeight) style:UITableViewStylePlain];
    _statisticalAnalysisTableView.delegate = self;
    _statisticalAnalysisTableView.dataSource = self;
    _statisticalAnalysisTableView.showsVerticalScrollIndicator = NO;
    _statisticalAnalysisTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_statisticalAnalysisTableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 生命周期函数调用方法
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[EMMAppChecker sharedInstance] startCheckVgoUpdate];
    timer = @"1";
    _menuListD = [[NSMutableArray alloc] init];
    _menuArrD = [[NSMutableArray alloc] init];
    [self postGetProjectListApi];
    [self creatNavigationController];
    timer = @"1";
    tierXZA = @"今天";
    //api
    _timerString = @"1";
    _mTimerString = @"1";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy"];
    NSDate * date = [NSDate date];//当前时间
    _yTimerString = [dateFormatter stringFromDate:date];
    _cjJSTimerString = nil;
    _cjKSTimerString = nil;
    _mzbJSTimerString = nil;
    _mzbSKTimerString = nil;
    
    _cjJSTimer1String = nil;
    _cjKSTimer1String = nil;
    _mzbJSTimer1String = nil;
    _mzbSKTimer1String = nil;
    
    _timerNameStr = [NSString stringWithFormat:@"今天成绩+本月指标+%@指标",_yTimerString];
    [self PostGetTimeConditionAnalysisApi];
}

#pragma mark - 切换项目IAP
- (void)postGetProjectListApi {
    [_menuListD removeAllObjects];
    [_menuArrD removeAllObjects];
    NSUserDefaults *us = [NSUserDefaults standardUserDefaults];
    NSMutableArray *projectDataArray = [us objectForKey:@"projectArray"];
    if (projectDataArray.count > 0 ) {
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        for (int i = 0; i < projectDataArray.count; i++) {
            NSData *data = projectDataArray[i];
            ProjectModel *model = [NSKeyedUnarchiver unarchiveObjectWithData:data];
            [_menuListD addObject:model.projectName];
            ProjectList *lsit = [[ProjectList alloc] init];
            lsit.projectName = model.projectName;
            lsit.projectId = model.projectId;
            lsit.projectCode = model.projectCode;
            [_menuArrD addObject:lsit];
            [arr addObject:lsit.projectCode];
        }
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
        NSString *projectCode = [userdf objectForKey:@"projectCode"];
        for (int i = 0; i < arr.count; i++) {
            NSString *pro = [arr objectAtIndex:i];
            if ([pro isEqualToString:projectCode]) {
                [userdf setObject:[NSString stringWithFormat:@"%d",i] forKey:@"indexString"];
                [userdf synchronize];
            }else {
            }
        }
    }
}

#pragma mark - 导航
- (void)creatNavigationController {
    [self updateNavBar];
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *token = [userdf objectForKey:@"is_login"];
    NSString *projectName;
    if ([NSString isStringEmpty2:token] == NO) {
        projectName  = [userdf objectForKey:@"projectName"];
    }
    NavigationView *view = [[NavigationView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH/2, 44) title:projectName colo:@"2"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button addTarget:self action:@selector(showPopover:) forControlEvents:UIControlEventTouchUpInside];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.frame = CGRectMake(0, 0, view.frame.size.width, 44.0);
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    button.tag = 101;
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [view addSubview:button];
    [self.navigationItem setTitleView:view];
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"ioc_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(priceRightClick:)];
    [self.navigationItem setRightBarButtonItem:rightItme];
}

- (void)priceRightClick:(UIButton *)btn {
    [self creatRemoveFromSuperview];
    if ([sfCZString isEqualToString:@"1"]) {
        _timerString = @"1";
        _mTimerString = @"1";
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy"];
        NSDate * date = [NSDate date];//当前时间
        _yTimerString = [dateFormatter stringFromDate:date];
        _cjKSTimerString = nil;
        _cjJSTimerString = nil;
        _mzbSKTimerString = nil;
        _mzbJSTimerString = nil;
        
        _cjJSTimer1String = nil;
        _cjKSTimer1String = nil;
        _mzbJSTimer1String = nil;
        _mzbSKTimer1String = nil;
    }
//    [self showHudInWindow:@"请稍等正在加载..."];
    
    //    shotImage = [[ShotImage shareInstance] shotWithView:self.view withScopeRect:CGRectMake(0, 0, _priceResultView.frame.size.width, _priceResultView.frame.size.height)];
    
    shotImage = [[ShotImage shareInstance] shotWithView:_staisCell];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"subShare.png"]];   // 保存文件的名称
    BOOL results = [UIImagePNGRepresentation(shotImage)writeToFile:filePath atomically:YES];
    
    [self savePhoto:filePath];
}

-(void)savePhoto:(NSString *)filePath {
    [self hideHud];
    NSURL *url = [NSURL fileURLWithPath:filePath];
    NSArray *objectsToShare = @[url];
    
    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
    
//    NSArray *excludedActivities = @[UIActivityTypePostToTwitter,
//                                    UIActivityTypePostToFacebook,
//                                    UIActivityTypePostToWeibo,
//                                    UIActivityTypeMessage,
//                                    UIActivityTypeMail,
//                                    UIActivityTypePrint,
//                                    UIActivityTypeCopyToPasteboard,
//                                    UIActivityTypeAssignToContact,
//                                    UIActivityTypeSaveToCameraRoll,
//                                    UIActivityTypeAddToReadingList,
//                                    UIActivityTypePostToFlickr,
//                                    UIActivityTypePostToVimeo,
//                                    UIActivityTypePostToTencentWeibo,
//                                    UIActivityTypeAirDrop,
//                                    UIActivityTypeOpenInIBooks];
    NSArray *excludedActivities = @[UIActivityTypePostToVimeo];

    controller.excludedActivityTypes = excludedActivities;
    
//    UIActivityViewControllerCompletionHandler myblock = ^(NSString *type,BOOL completed){
//        NSLog(@"%d %@",completed,type);
//        if (completed == NO ) {
//            [self showToast:@"取消发送"];
//        }else {
//            [self showToast:@"成功发送"];
//        }
//    };
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        UIActivityViewControllerCompletionWithItemsHandler myblock = ^(NSString *activityType,BOOL completed,NSArray *returnedItems,NSError *activityError) {
            NSLog(@"activityType :%@", activityType);
            if (completed)  {
                NSLog(@"completed");
                [self showToast:@"成功发送"];

            } else {
                NSLog(@"cancel");
                [self showToast:@"取消发送"];
            }
        };
        controller.completionWithItemsHandler = myblock;
    } else {
        UIActivityViewControllerCompletionHandler myblock = ^(NSString *activityType,BOOL completed) {
            NSLog(@"activityType :%@", activityType);
            if (completed) {
                NSLog(@"completed");
                [self showToast:@"成功发送"];
            } else {
                NSLog(@"cancel");
                [self showToast:@"取消发送"];
            }
        };
        controller.completionHandler = myblock;
    }
    [self presentViewController:controller animated:YES completion:nil];

}


#pragma mark - 显示app商家列表
- (void)showPopover:(UIButton *)button {
    [self creatRemoveFromSuperview];
    if ([sfCZString isEqualToString:@"1"]) {
        _timerString = @"1";
        _mTimerString = @"1";
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy"];
        NSDate * date = [NSDate date];//当前时间
        _yTimerString = [dateFormatter stringFromDate:date];
        _cjKSTimerString = nil;
        _cjJSTimerString = nil;
        _mzbSKTimerString = nil;
        _mzbJSTimerString = nil;
        
        _cjJSTimer1String = nil;
        _cjKSTimer1String = nil;
        _mzbJSTimer1String = nil;
        _mzbSKTimer1String = nil;
    }
    if (_isShowUI == YES) {
        [self removeMenuLitsViewSubView];
        [self creatView];
        _isShowUI = NO;
    }else {
        [self removeMenuLitsViewSubView];
        _isShowUI = YES;
    }
}

#pragma mark - 创建项目切换View
- (void)creatView {
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *num = [userdf objectForKey:@"indexString"];
    NSInteger h = 0;
    if (_menuListD.count > 6) {
        h = 6*50;
    }else {
        h = _menuListD.count * 50;
    }
    _menuD = [[MenuLitsView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight) items:_menuListD indet:num isShowUI:YES guodu:h];
    _menuD.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:_menuD];
    __weak MenuLitsView *weakSelf = _menuD;
    [weakSelf setMenuLitsBlock:^(NSString *title, NSString *indet) {
        if ([NSString isStringEmpty2:title] == NO) {
            _isShowUI = YES;
        }else {
            _isShowUI = YES;
        }
        if ([NSString isStringEmpty2:indet] == NO) {
            ProjectList *lsit1 = _menuArrD[[indet intValue]];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            [userdf setObject:lsit1.projectCode forKey:@"projectCode"];
            [userdf setObject:lsit1.projectId forKey:@"projectId"];
            [userdf setObject:lsit1.projectName forKey:@"projectName"];
            [userdf setObject:indet forKey:@"indexString"];
            [userdf synchronize];
            [self creatNavigationController];
            [self PostGetTimeConditionAnalysisApi];
            [[MerchantResourceVModel merchantResourceVModel] startMerchantResourceVModel];
        }
        [weakSelf removeFromSuperview];
    }];
}

#pragma mark - 删除项目切换View
- (void)removeMenuLitsViewSubView {
    [_menuD removeFromSuperview];
    _menuD = nil;
}


#pragma mark - 查询会员成绩信息Api调用方法
- (void)PostGetTimeConditionAnalysisApi {
    [self showHudInWindow:@"正在加载请稍等..."];
    GetTimeConditionAnalysisApi *api = [[GetTimeConditionAnalysisApi alloc]initWithType:nil
                                                                         gradesTimeType:_timerString
                                                                        gradesStartTime:_cjKSTimerString
                                                                          gradesEndTime:_cjJSTimerString
                                                                            monthlyType:_mTimerString
                                                                       monthlyStartTime:_mzbSKTimerString
                                                                         monthlyEndTime:_mzbJSTimerString
                                                                               yearTime:_yTimerString];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetTimeConditionAnalysisApi *result = (GetTimeConditionAnalysisApi *)request;
        if (result.isSuccess) {
            GetTimeConditionAnalysis *get = result.resultData;
            _getTimeConditionAnalysis = get;
        } else {
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [_statisticalAnalysisTableView reloadData];
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark----tableViewDelegate
//返回几个表头
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

//每一个表头下返回几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 2;
}

//设置表头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 0.1f;
}

//Section Footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1f;
}

//设置view，将替代titleForHeaderInSection方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
   
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return 905;
    }
    return 265;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"StatisticalAnalysisOneCell";
    StatisticalAnalysisOneCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"StatisticalAnalysisOneCell" owner:self options:nil] lastObject];
    }
    cell.statisicalDelegate = self;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == 0) {
        static NSString *CellIdentifier = @"StatisticalAnalysisCellId";
        _staisCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (_staisCell == nil) {
            _staisCell = [[[NSBundle mainBundle] loadNibNamed:@"StatisticalAnalysisCell" owner:self options:nil] lastObject];
        }
        _staisCell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _staisCell.timerLabel.text = _timerNameStr;
        
        //来电
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.callNum] == NO) {
            _staisCell.callNumLabel.text = _getTimeConditionAnalysis.callNum;
        }else {
            _staisCell.callNumLabel.text = @"0";
        }
        
        //来电有效
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.callValidNum] == NO) {
            _staisCell.effectiveNumLabel.text = _getTimeConditionAnalysis.callValidNum;
        }else {
            _staisCell.effectiveNumLabel.text = @"0";
        }
        
        //来访
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.visitNum] == NO) {
            _staisCell.visitNumLabel.text = _getTimeConditionAnalysis.visitNum;
        }else {
            _staisCell.visitNumLabel.text = @"0";
        }
        
        //来电有效
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.freshCusVisitNum] == NO) {
            _staisCell.khNewNumLabel.text = _getTimeConditionAnalysis.freshCusVisitNum;
        }else {
            _staisCell.khNewNumLabel.text = @"0";
        }
        
        //来电有效
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.oldCusVisitNum] == NO) {
            _staisCell.khOldNumLabel.text = _getTimeConditionAnalysis.oldCusVisitNum;
        }else {
            _staisCell.khOldNumLabel.text = @"0";
        }
        
        //认筹
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.depositNum] == NO) {
            _staisCell.rcNumLabel.text = _getTimeConditionAnalysis.depositNum;
        }else {
            _staisCell.rcNumLabel.text = @"0";
        }
        
        //认购数量
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.subscribeNum] == NO) {
            _staisCell.rgNumLabel.text = _getTimeConditionAnalysis.subscribeNum;
        }else {
            _staisCell.rgNumLabel.text = @"0";
        }
        
        //认购金额
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.subscribeAmount] == NO) {
            _staisCell.rgMoneyLabel.text = _getTimeConditionAnalysis.subscribeAmount;
        }else {
            _staisCell.rgMoneyLabel.text = @"0";
        }
        
        //签约数
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.signedNum] == NO) {
            _staisCell.qyNumLabel.text = _getTimeConditionAnalysis.signedNum;
        }else {
            _staisCell.qyNumLabel.text = @"0";
        }
        
        //签约金额
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.signedAmount] == NO) {
            _staisCell.qyMoneyLabel.text = _getTimeConditionAnalysis.signedAmount;
        }else {
            _staisCell.qyMoneyLabel.text = @"0";
        }
        
        //回款金额
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.paymentAmount] == NO) {
            _staisCell.huiKMoneyLabel.text = _getTimeConditionAnalysis.paymentAmount;
        }else {
            _staisCell.huiKMoneyLabel.text = @"0";
        }
        
        //月销售百分比
        NSString *monthlySalesRate = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.monthlySalesRate] == NO) {
            monthlySalesRate = _getTimeConditionAnalysis.monthlySalesRate;
        }else {
            monthlySalesRate = @"0";
        }
        //月销售指标
        NSString *monthlySalesTarget = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.monthlySalesTarget] == NO) {
            monthlySalesTarget = _getTimeConditionAnalysis.monthlySalesTarget;
        }else {
            monthlySalesTarget = @"0";
        }
        //月回款百分比
        NSString *monthlyPaymentRate = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.monthlyPaymentRate] == NO) {
            monthlyPaymentRate = _getTimeConditionAnalysis.monthlyPaymentRate;
        }else {
            monthlyPaymentRate = @"0";
        }
        //月回款指标
        NSString *monthlyPaymentTarget = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.monthlyPaymentTarget] == NO) {
            monthlyPaymentTarget = _getTimeConditionAnalysis.monthlyPaymentTarget;
        }else {
            monthlyPaymentTarget = @"0";
        }
        //月综合百分比
        NSString *monthlyGeneralRate = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.monthlyGeneralRate] == NO) {
            monthlyGeneralRate = _getTimeConditionAnalysis.monthlyGeneralRate;
        }else {
            monthlyGeneralRate = @"0";
        }
        //月综合指标
        NSString *monthlyGeneralTarget = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.monthlyGeneralTarget] == NO) {
            monthlyGeneralTarget = _getTimeConditionAnalysis.monthlyGeneralTarget;
        }else {
            monthlyGeneralTarget =@"0";
        }
        
        
        //年销售百分比
        NSString *yearSalesRate = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.yearSalesRate] == NO) {
            yearSalesRate = _getTimeConditionAnalysis.yearSalesRate;
        }else {
            yearSalesRate = @"0";
        }
        //年销售指标
        NSString *yearSalesTarget = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.yearSalesTarget] == NO) {
            yearSalesTarget = _getTimeConditionAnalysis.yearSalesTarget;
        }else {
            yearSalesTarget = @"0";
        }
        //年回款百分比
        NSString *yearPaymentRate = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.yearPaymentRate] == NO) {
            yearPaymentRate = _getTimeConditionAnalysis.yearPaymentRate;
        }else {
            yearPaymentRate = @"0";
        }
        //年回款指标
        NSString *yearPaymentTarget = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.yearPaymentTarget] == NO) {
            yearPaymentTarget = _getTimeConditionAnalysis.yearPaymentTarget;
        }else {
            yearPaymentTarget = @"0";
        }
        //年综合百分比
        NSString *yearGeneralRate = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.yearGeneralRate] == NO) {
            yearGeneralRate = _getTimeConditionAnalysis.yearGeneralRate;
        }else {
            yearGeneralRate = @"0";
        }
        //年综合指标
        NSString *yearGeneralTarget = nil;
        if ([NSString isStringEmpty2:_getTimeConditionAnalysis.yearGeneralTarget] == NO) {
            yearGeneralTarget = _getTimeConditionAnalysis.yearGeneralTarget;
        }else {
            yearGeneralTarget =@"0";
        }
        
        [_staisCell creatInitWithmXSPercentage:monthlySalesRate
                                mXSContrastNum:[NSString stringWithFormat:@"(%@万)",monthlySalesTarget]
                                 mHKPercentage:monthlyPaymentRate
                                mHKContrastNum:[NSString stringWithFormat:@"(%@万)",monthlyPaymentTarget]
                                 mZHPercentage:monthlyGeneralRate
                                mZHContrastNum:[NSString stringWithFormat:@"(%@万)",monthlyGeneralTarget]
                                 yXSPercentage:yearSalesRate
                                yXSContrastNum:[NSString stringWithFormat:@"(%@万)",yearSalesTarget]
                                 yHKPercentage:yearPaymentRate
                                yHKContrastNum:[NSString stringWithFormat:@"(%@万)",yearPaymentTarget]
                                 yZHPercentage:yearGeneralRate
                                yZHContrastNum:[NSString stringWithFormat:@"(%@万)",yearGeneralTarget]];
        
        [_staisCell.seleTimerBtn addTarget:self action:@selector(seleTimerBtnClikc:) forControlEvents:UIControlEventTouchUpInside];
        
        return _staisCell;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   
}

- (void)initwithcollecttionIdex:(NSInteger)collectionindex {
    NSLog(@"------>>> %ld",collectionindex);
    if (collectionindex == 0) {
        //客户分析
        EMMAnalysisViewController *evc = [[EMMAnalysisViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 1) {
        //已签约未回款
        EMMNotSignedBackViewController *evc = [[EMMNotSignedBackViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 2) {
        //工作量统计
        WorkloadStatisticsViewController *evc = [[WorkloadStatisticsViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 3) {
        //销售指标
        EMMSalesTargetViewController *evc = [[EMMSalesTargetViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 4) {
        //成交房源
        DealPropertyTypeAnalysisViewController *evc = [[DealPropertyTypeAnalysisViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 5) {
        //存量时间分析
        StockTimeAnalysisViewController *evc = [[StockTimeAnalysisViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 6) {
        //算价分析
        CalculationPAViewController *evc = [[CalculationPAViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:evc animated:YES];
       
    } else if (collectionindex == 7) {
        //成交房源
        StockAvailabilityViewController *evc = [[StockAvailabilityViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        evc.isStock = NO;
        [self.navigationController pushViewController:evc animated:YES];
    } else if (collectionindex == 8) {
        //存量房源
        StockAvailabilityViewController *evc = [[StockAvailabilityViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        evc.isStock = YES;
        [self.navigationController pushViewController:evc animated:YES];
    }
}


- (void)seleTimerBtnClikc:(UIButton *)btn {
    NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"今天",@"昨天",@"本周",@"上周",@"本月",@"上月",@"近三月",@"今年",nil];
    NSMutableArray *arr2 = [NSMutableArray arrayWithObjects:@"本月",@"上月",@"近三月",@"近六月",nil];

//    _cView = [[ChooseView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight) timeArray:arr timeIndex:[_timerString floatValue]-1 indexArray:arr2 indexIndex:[_mTimerString floatValue] - 1];
    _cView = [[ChooseView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight)
                                     timeArray:arr
                                     timeIndex:[_timerString floatValue]-1
                                     beginTime:_cjKSTimer1String
                                       endTime:_cjJSTimer1String
                                    indexArray:arr2
                                    indexIndex:[_mTimerString floatValue] - 1
                                mouthBeginTime:_mzbSKTimer1String
                                  mouthEndTime:_mzbJSTimer1String
                                       yearStr:_yTimerString];
    
    _cView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:_cView];
    __block EMMStatisticalAnalysisViewController *blockSelf = self;
    [_cView setChooseBlock:^(NSInteger index, NSString *str1, NSString *str2, NSInteger index2 ,NSString *str11, NSString *str22, NSString *yearStr,NSString *which) {//which 0 为确定 1为空白消失
        NSLog(@"%ld - %@ - %@ - %ld - %@ - %@ - %@ - %@",index,str1,str2,index2,str11,str22,yearStr,which);
        if ([which isEqual:@"1"]) {
            _timerString = @"1";
            _mTimerString = @"1";
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"yyyy"];
            NSDate * date = [NSDate date];//当前时间
            _yTimerString = [dateFormatter stringFromDate:date];
            _cjKSTimerString = nil;
            _cjJSTimerString = nil;
            _mzbSKTimerString = nil;
            _mzbJSTimerString = nil;
            
            _cjKSTimer1String = nil;
            _cjJSTimer1String = nil;
            _mzbSKTimer1String = nil;
            _mzbJSTimer1String = nil;
            
            return ;
        }
        _timerString = [NSString stringWithFormat:@"%ld",index+1];
        
        if ([NSString isStringEmpty2:str1] == NO && [NSString isStringEmpty2:str2] == NO) {
            _cjKSTimer1String = str1;
            _cjJSTimer1String = str2;
            
            //成绩开始时间
            NSArray *cjArr1 = [str1 componentsSeparatedByString:@"-"];
            //月份
            NSString *str = nil;
            if ([cjArr1[1] integerValue] < 10) {
                str = [NSString stringWithFormat:@"0%@",cjArr1[1]];
            }else {
                str = [NSString stringWithFormat:@"%@",cjArr1[1]];
            }
            //日
            NSString *str1 = nil;
            if ([cjArr1[2] integerValue] < 10) {
                str1 = [NSString stringWithFormat:@"0%@",cjArr1[2]];
            }else {
                str1 = [NSString stringWithFormat:@"%@",cjArr1[2]];
            }
            _cjKSTimerString = [NSString stringWithFormat:@"%@-%@-%@",cjArr1[0],str,str1];
            
            //结束时间
            NSArray *cjArr2 = [str2 componentsSeparatedByString:@"-"];
            //月份
            NSString *str3 = nil;
            if ([cjArr2[1] integerValue] < 10) {
                str3 = [NSString stringWithFormat:@"0%@",cjArr2[1]];
            }else {
                str3 = [NSString stringWithFormat:@"%@",cjArr2[1]];
            }
            //日
            NSString *str4 = nil;
            if ([cjArr2[2] integerValue] < 10) {
                str4 = [NSString stringWithFormat:@"0%@",cjArr2[2]];
            }else {
                str4 = [NSString stringWithFormat:@"%@",cjArr2[2]];
            }
            _cjJSTimerString = [NSString stringWithFormat:@"%@-%@-%@",cjArr2[0],str3,str4];
            _timerString = nil;
        }else {
            _cjKSTimerString = nil;
            _cjJSTimerString = nil;
            _cjKSTimer1String = nil;
            _cjJSTimer1String = nil;
        }
      
        _mTimerString = [NSString stringWithFormat:@"%ld",index2+1];

        if ([NSString isStringEmpty2:str11] == NO && [NSString isStringEmpty2:str22] == NO) {
            _mzbSKTimer1String = str11;
            _mzbJSTimer1String = str22;
            
            //月指标开始时间
            NSArray *cjArr1 = [str11 componentsSeparatedByString:@"-"];
            //月份
            NSString *str = nil;
            if ([cjArr1[1] integerValue] < 10) {
                str = [NSString stringWithFormat:@"0%@",cjArr1[1]];
            }else {
                str = [NSString stringWithFormat:@"%@",cjArr1[1]];
            }
            
            _mzbSKTimerString = [NSString stringWithFormat:@"%@-%@",cjArr1[0],str];
            
            //月指标结束时间
            NSArray *cjArr2 = [str22 componentsSeparatedByString:@"-"];
            //月份
            NSString *str2 = nil;
            if ([cjArr2[1] integerValue] < 10) {
                str2 = [NSString stringWithFormat:@"0%@",cjArr2[1]];
            }else {
                str2 = [NSString stringWithFormat:@"%@",cjArr2[1]];
            }
          
            _mzbJSTimerString = [NSString stringWithFormat:@"%@-%@",cjArr2[0],str2];
            _mTimerString = nil;
        }else {
            _mzbSKTimerString = nil;
            _mzbJSTimerString = nil;
            _mzbSKTimer1String = nil;
            _mzbJSTimer1String = nil;
        }
        
        _yTimerString = yearStr;
        NSString *strN1 = nil;
        NSString *strN2 = nil;
        if ([NSString isStringEmpty2:str1] == NO && [NSString isStringEmpty2:str2] == NO) {
            strN1 = [NSString stringWithFormat:@"(%@)-(%@)",str1,str2];
        }else {
            strN1 = [arr objectAtIndex:index];
        }
        
        if ([NSString isStringEmpty2:str11] == NO && [NSString isStringEmpty2:str22] == NO) {
            strN2 = [NSString stringWithFormat:@"(%@)-(%@)",str11,str22];
        }else {
            strN2 = [arr2 objectAtIndex:index2];
        }
        
        _timerNameStr = [NSString stringWithFormat:@"%@成绩+%@指标+%@指标",strN1,strN2,_yTimerString];
        [blockSelf.statisticalAnalysisTableView reloadData];
        [blockSelf PostGetTimeConditionAnalysisApi];
    }];
    
    [_cView setChooseViewBlock:^(NSString *str) {
        sfCZString = str;
    }];
}

- (void)creatRemoveFromSuperview {
    [_cView removeFromSuperview];
    _cView = nil;
}

@end
